package com.baitiaojun.elasticsearch.api.impl;

import com.baitiaojun.api.domain.video.VideoChildComment;
import com.baitiaojun.api.domain.video.VideoComment;
import com.baitiaojun.api.exception.ConditionException;
import com.baitiaojun.api.vo.JsonRes;
import com.baitiaojun.api.vo.PageInfo;
import com.baitiaojun.elasticsearch.api.VideoCommentApi;
import com.baitiaojun.elasticsearch.service.VideoCommentService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * @类名 VideoCommentApiImpl
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2022/12/26 21:38
 * @版本 1.0
 */
@ApiIgnore
@RestController
public class VideoCommentApiImpl implements VideoCommentApi {

    @Autowired
    private VideoCommentService videoCommentService;

    @Override
    public JsonRes saveVideoComment(VideoComment videoComment) throws ConditionException {
        videoCommentService.saveParentVideoComment(videoComment);
        return JsonRes.builder().success();
    }

    @Override
    public JsonRes saveChildVideoComment(VideoChildComment videoChildComment) throws ConditionException {
        videoCommentService.saveChildVideoComment(videoChildComment);
        return JsonRes.builder().success();
    }

    @Override
    public VideoComment getParentVideoComment(Long id, Long videoId) {
        return videoCommentService.getParentVideoComment(id, videoId);
    }

    @Override
    public List<VideoComment> getParentVideoCommentList(Integer pageNo, Integer size, Long videoId) {
        return videoCommentService.getParentVideoCommentList(pageNo, size, videoId);
    }

    @Override
    public List<VideoChildComment> getChildVideoCommentList(Set<Long> ids) throws IOException {
        return videoCommentService.getChildVideoCommentList(ids);
    }

    @Override
    public PageInfo getPageChildVideoCommentList(Integer pageNo, Integer pageSize, Long videoId, Long rootId) {
        return videoCommentService.getPageChildVideoCommentList(pageNo, pageSize, videoId, rootId);
    }

    @Override
    public void removeVideoChildComment(Long id) {
        videoCommentService.removeVideoChildComment(id);
    }

    @Override
    public void removeVideoComment(Long id) {
        videoCommentService.removeVideoComment(id);
    }

    @Override
    public JsonRes getVideoChildComment(Long id) throws ConditionException {
        VideoChildComment videoChildComment = videoCommentService.getVideoChildComment(id);
        if (ObjectUtils.isEmpty(videoChildComment)) {
            throw new ConditionException();
        }
        return JsonRes.builder().success();
    }

    @Override
    public List<VideoComment> getVideoCommentList(Long userId) throws IOException {
        return videoCommentService.getVideoCommentList(userId);
    }

    @Override
    public List<VideoChildComment> getVideoChildCommentList(Set<Long> ids) {
        return videoCommentService.getVideoChildCommentList(ids);
    }
}
